package com.compass.mobile.ui.activity.static_page

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.leanback.widget.ArrayObjectAdapter
import androidx.leanback.widget.BaseGridView
import androidx.leanback.widget.FocusHighlight
import androidx.leanback.widget.FocusHighlightHelper
import androidx.leanback.widget.OnChildViewHolderSelectedListener
import androidx.recyclerview.widget.RecyclerView
import com.compass.mobile.callback.OnItemClickListener
import com.compass.mobile.databinding.ActivityDoctorStaticBinding
import com.compass.mobile.framework.base.BaseVBActivity
import com.compass.mobile.framework.utils.dpToPx
import com.compass.mobile.models.Doctor
import com.compass.mobile.presenters.DoctorStaticPresenter
import com.compass.mobile.widget.MyBridgeAdapter

/**
 * Description：医生静态页面
 * Date:2024/8/20 13:35
 */
class DoctorStaticActivity : BaseVBActivity<ActivityDoctorStaticBinding>() {

    companion object {
        fun start(context: Context) {
            val intent = Intent(context, DoctorStaticActivity::class.java)
            context.startActivity(intent)
        }
    }

    private var doctors: MutableList<Doctor> = mutableListOf()
    private lateinit var arrayObjectAdapter: ArrayObjectAdapter


    override fun initView(savedInstanceState: Bundle?) {
       val doctor=Doctor("1768908657983885379","马洁","https://guoyi.oss-cn-beijing.aliyuncs.com/d6f2f4302b37bf7da9ce578c6e886d4fb45f514b8633aa8877abd6afb01251b7.jpg"
       ,"1787668465567748098","神经内科","神经内科","主治医师","5","20"
       ,"1","高新医院的医生，全科医生，工作经验10余年","127","50","86","88"
       ,"55","三甲","西安高新医院","1","1","1","1","1","1",
           "0.01","0.01","0.01","擅长呼吸系统、心血管系统、脑梗死、糖尿病、高血压、慢性肾功能衰竭等慢性病诊治及管理，临床经验丰富，擅长内科常见疾病的全程个体化精准管理及规范化治疗。"
       ,"深耕全科医疗科领域多年的专业医生。在肾功能不全综合治疗和糖尿病药物治疗方面有着丰富的经验，并且注重个体化治疗方案的制定","1","20")

        doctors.add(doctor)
        doctors.add(doctor)
        doctors.add(doctor)
        doctors.add(doctor)
        doctors.add(doctor)
        doctors.add(doctor)

        initSpecialColumn()


    }




    private val onItemClickListener: OnItemClickListener = object : OnItemClickListener {
        override fun onItemClick(position: Int, view: View) {
            val item = doctors[position]



        }
    }


    @SuppressLint("RestrictedApi")
    fun initSpecialColumn() {
        mBinding.caseItem.setNumColumns(3)
        mBinding.caseItem.horizontalSpacing = dpToPx(10)
        mBinding.caseItem.verticalSpacing = dpToPx(10)
        val departmentIntroductionPresenter = DoctorStaticPresenter("2")
        arrayObjectAdapter = ArrayObjectAdapter(departmentIntroductionPresenter)
        val itemBridgeAdapter = MyBridgeAdapter(
            this,
            arrayObjectAdapter, onItemClickListener
        )
        mBinding.caseItem?.setOnChildViewHolderSelectedListener(onChildViewHolderSelectedListener)
        mBinding.caseItem.setAdapter(itemBridgeAdapter)
        mBinding.caseItem.setFocusScrollStrategy(BaseGridView.FOCUS_SCROLL_ITEM)
        arrayObjectAdapter.addAll(0, doctors)
        FocusHighlightHelper.setupBrowseItemFocusHighlight(
            itemBridgeAdapter,
            FocusHighlight.ZOOM_FACTOR_NONE, false
        )
        mBinding.caseItem.requestFocus()
    }

    private var isMoveTop = true
    private val onChildViewHolderSelectedListener: OnChildViewHolderSelectedListener = object :
        OnChildViewHolderSelectedListener() {
        override fun onChildViewHolderSelected(
            parent: RecyclerView?,
            child: RecyclerView.ViewHolder?,
            position: Int,
            subposition: Int
        ) {
            if (position < 3) {
                isMoveTop = true
            } else {
                isMoveTop = false
            }
        }
    }


}